<template>
<!--  详情页面的弹窗-->
  <el-dialog :title="dialogTitle" style="width:600px;padding:40px;" v-model="dialogVisible" :before-close="handleClose">
    <el-text>执照</el-text>
    <img :src="BASE_URL + ShowCompany.occupationPhoto" style="width:100%;height:100%;"/>
  </el-dialog>


  <!-- 公司信息表格 -->
  <el-card style="margin:20px;">
    <el-table :data="CompanyArray">
      <el-table-column type="index" label="编号" width="80" align="center"/>
      <el-table-column prop="corporateName" label="公司名称" align="center"/>
      <el-table-column prop="corporateLevel" label="公司级别" align="center"/>
      <!--      <el-table-column prop="coverPhoto" label="封面图片" align="center"/>-->
      <el-table-column prop="companySize" label="公司规模" align="center"/>
      <el-table-column prop="industryClassification" label="行业分类" align="center"/>
      <!--      <el-table-column prop="photoShow" label="图片展示" align="center"/>-->
      <el-table-column prop="createTime" label="申请时间" align="center"/>
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button link type="primary" size="small" @click="moreInfo(scope.row.id)" style="color:#5B63B7">查看执照</el-button>
          <el-button link type="primary" size="small" @click="pass(scope.row.id)" style="color:#5B63B7">通过</el-button>
          <el-button link type="primary" size="small" @click="dispass(scope.row.id)" style="color:#5B63B7">驳回</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-card>
</template>

<script setup>
import {onMounted, ref} from "vue";
import axios from "axios";
import {ElMessage} from "element-plus";
import qs from "qs";
const dialogTitle = ref('公司详情信息');
const dialogVisible = ref(false);
//实现取消按钮的功能
const handleClose = ()=>{
  if(confirm('是否关闭本窗口?')){
    //用户确认关闭后,将审批弹窗与确认驳回弹窗一起关掉
    dialogVisible.value = false;

  }
}

onMounted(()=>{
  loadApprovalCompany();
})

//定义数组用来装用户列表信息
const CompanyArr = ref([]);
const CompanyArray = ref([]);
const ShowCompany = ref({})

const loadApprovalCompany = () => {
  axios.get(BASE_URL + '/v1/company/selectApproval').then((response)=>{
    if (response.data.code === 2000){
      CompanyArr.value = response.data.data;
      for (let i = 0; i < CompanyArr.value.length; i++){
        if(CompanyArr.value[i].status == 0){
          CompanyArray.value.push(CompanyArr.value[i]);
        }
      }
    }
  })
}

const pass = (id) =>{
  //将id转为Long类型
  axios.post(BASE_URL + '/v1/company/pass?id='+id).then((response)=>{
    if (response.data.code === 2000){
      ElMessage.success('审核通过');
      loadApprovalCompany();
      window.location.href = window.location.href;
    }
  })
}

const dispass = (id) =>{
  //将id转为Long类型
  axios.post(BASE_URL + '/v1/company/dispass?id='+id).then((response)=>{
    if (response.data.code === 2000){
      ElMessage.success('审核驳回');
      loadApprovalCompany();
      window.location.href = window.location.href;
    }
  })
}

const moreInfo = (id) =>{
  dialogVisible.value = true;
  axios.get(BASE_URL + '/v1/company/selectApprovalMore?id='+id).then((response)=>{
    if(response.data.code === 2000){
      ShowCompany.value = response.data.data;
      console.log("执照地址" + ShowCompany.value.occupationPhoto);
    }
  })
}

</script>

<style scoped>

</style>